#include <REGX52.H>
#include "AT24C02.h"
#include "Delay.h"
#include "LCD1602.h"
#include "Key.h"
void main()
{
	unsigned char x = 0;
	unsigned int y = 0;
	LCD_Init();
//	LCD_ShowString(1,1,"Hello");
//	AT24C02_WriteByte(0,67);
//	Delay(5);
//	x = AT24C02_ReadByte(0);
//	LCD_ShowNum(2,1,x,2);
	while(1)
	{
		LCD_ShowNum(1,1,y,5);
		x=Key();
		if(x==1)
		{
			y++;
		}
		if(x==2)
		{
			y--;
		}
		if(x==3)
		{
			AT24C02_WriteByte(0,y%256);//只能存8位数据//int类型数据存不下需要分两次存（c51中unsigned int需要2个字节大小存储）
			Delay(5);
			AT24C02_WriteByte(1,y/256);//前八位
			Delay(5);
			LCD_ShowString(2,1,"OK");
			Delay(1000);
			LCD_ShowString(2,1,"  ");
		}
		if(x==4)
		{
			y=AT24C02_ReadByte(0);
			y|=AT24C02_ReadByte(1)<<8;
			LCD_ShowNum(1,1,y,5);
			LCD_ShowString(2,1,"DU OK");
			Delay(1000);
			LCD_ShowString(2,1,"     ");
		}
	}
}